package database;
import java.math.BigDecimal;
import java.sql.*;
import java.util.Random;

public class MySQLDemo {
    public static void main(String[] args) {
        Connection connection = null;
        Statement statement = null;
        ResultSet resultSet = null;

        try{
            Class.forName("com.mysql.cj.jdbc.Driver");
            String url = "jdbc:mysql://127.0.0.1:3306/learning";

            String user = "root";//MySQL用户名
            String password = "123456";//MySQL登录密码，自己设置

            connection = DriverManager.getConnection(url,user,password);

            statement = connection.createStatement();

            int userId = 1;
            float money = 1.5F;
            Random consumeCount = new Random();
            Random vipLevel = new Random();

            while(userId < 100) {
                String sql = String.format("insert into vip values(%d, %f, %d, %d)",
                        userId, money, vipLevel.nextInt(5), consumeCount.nextInt(100));

                statement.executeUpdate(sql);
                userId += 1;
                money += 10.5;
            }


        } catch(Exception e){
            e.printStackTrace();
        } finally {
            System.out.println("mysqlDemo have been completed!");
        }
    }
}
